package com.neusoft.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.neuedu.utils.CloseUtils;
import com.neuedu.utils.GetConnectionUntils;
import com.neusoft.entity.User;

public class DaoImpl implements UserDao{

	@Override
	public  boolean checkUser(User user) {
		Connection OneConnection = GetConnectionUntils.getOneConnection();//拿到Connection
		String sql ="select * from user where user_name = ? and user_password = ?";//sql语句
		PreparedStatement prepareStatement = null;
		ResultSet execute = null;
		try {
			prepareStatement=OneConnection.prepareStatement(sql);//Connection对象拿到prepareStatement
			prepareStatement.setString(1, user.getUserName());
			prepareStatement.setString(2, user.getUserPassword());
			execute = prepareStatement.executeQuery();
			if(execute.next())//遍历ResultSet对象
			{
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			CloseUtils.close(OneConnection,prepareStatement,execute);//关闭资源
		}
		return false;
	}
	public static void main(String[] args) {
		User user = new User("马化腾","mysql");
		boolean checkUser= new DaoImpl().checkUser(user);
		System.out.println(checkUser);
	}
}

